﻿<?php
//taisyta 2011.05.10
include("config.php");
if (!isset($_SESSION["user"]) || $_SESSION["user"] == "") header('Location: index.php');
include("header.php");
include("menu.php");
include("classes/class.phpmailer.php");

$db_www = new DB($server_username,$server_pass,$server_db,$server,$driver);
if ($db_www->isConnected()) {	
	$oinfo = $db_www->returnInfo($o_query);	
	if (!empty($oinfo)) {
		$o_query = str_replace("<kodas>", $oinfo["N23_REIKSME1"], $ii_query);
		$ourinfo = $db_www->returnInfo($o_query);	
		
		$s_query = str_replace("<kodas>", $oinfo["N23_REIKSME1"], $s_query);
		$saskinfo = $db_www->returnInfo($s_query);
	}

	$i_query = str_replace("<kodas>", $_SESSION['user'], $i_query);
	//echo $i_query;
	$minfo = $db_www->returnInfo($i_query);	

	
} else {
	die("Klientų aptarnavimo sistema laikinai neveikia.");
}

?>
<br>
<table class="innercont" cellspacing="0" cellpadding="5">
<?php

$pforma = "";
if (isset($_POST["but"])) {
		$u_query = str_replace("<get_username>", $_SESSION['user'], $u_query);
		$u_query = str_replace("<get_password>", addslashes_mssql($_POST["old"]), $u_query);	
		$info = $db_www->returnInfo($u_query);									
		if (!empty($info)) {
			if ($_POST["new1"] != $_POST["new2"]) {
				$pforma = "<p class='err'>Naujas slaptažodis nesutampa!</p>";
				logAction("Naujas slaptažodis nesutampa!",4);
			} else {
				$pass_query = str_replace("<get_username>", $_SESSION['user'], $pass_query);
				$pass_query = str_replace("<get_password>", addslashes_mssql($_POST["old"]), $pass_query);	
				$pass_query = str_replace("<password>", addslashes_mssql($_POST["new1"]), $pass_query);	
				$db_www->execute($pass_query);	
				
				
				$mail = new PHPMailer(); 
				$mail->CharSet = "UTF-8";
				$mail->Host = $smtp_server;
				$mail->Port = $smtp_port;
				$mail->IsSMTP(); // send via SMTP
				//$mail->SMTPDebug  = 2;
				if ($smtp_user != "") {
					$mail->SMTPAuth = true; // turn on SMTP authentication
					$mail->Username = $smtp_user; // SMTP username
					$mail->Password = $smtp_pass; // SMTP password
				}	else {
					$mail->SMTPAuth = false; // turn on SMTP authentication
				}							
				//$email="darmik@gmail.com"; // Recipients email ID
				$email=$info["email"]; // Recipients email ID				
				$mail->From = $webmaster_email;
				$mail->FromName = $webmaster_name;
				$mail->AddAddress($email);
				$mail->AddReplyTo($webmaster_email,$webmaster_name);
				//$mail->WordWrap = 50; // set word wrap
				$mail->IsHTML(true); // send as HTML
				$mail->Subject = $change_pass_subject;
				$change_pass_body = str_replace("<username>",$_SESSION['user'], $change_pass_body);
				$change_pass_body = str_replace("<password>", $_POST["new1"], $change_pass_body);
				$mail->Body = $change_pass_body; //HTML Body
				$mail->AltBody = $change_pass_body; //Text Body
				if(!$mail->Send())
				{
					$pforma = "Mailer Error: " . $mail->ErrorInfo;			
				}
				else
				{
					$pforma = "<p class='err'>Slaptažodis pakeistas sėkmingai!</p>";
					logAction("Slaptažodis pakeistas sėkmingai!",4);
				}				

			}
		} else {
			$pforma = "<p class='err'>Neteisingas senas slaptažodis!</p>";
			logAction("Neteisingas senas slaptažodis!",4);
		}
}
$pforma .= '<form method="post" action="information.php">';
$pforma .= '<input type="hidden" name="but" value="1">';
$pforma .= '<table class="params chpass">';
$pforma .= '<tr><td colspan="2" class="formhead" style="text-align:left;">Keisti slaptažodį</td></tr>';
$pforma .= '<tr><td class="form" style="text-align:left;">Įveskite seną slaptažodį</td><td><input type="password" name="old" class="input"></td></tr>';
$pforma .= '<tr><td class="form" style="text-align:left;">Įveskite naują slaptažodį</td><td><input type="password" name="new1" class="input"></td></tr>';
$pforma .= '<tr><td class="form" style="text-align:left;">Pakartokite naują slaptažodį</td><td><input type="password" name="new2" class="input"></td></tr>';
$pforma .= '<tr><td colspan="2" style="text-align:right;"><button class=\'but bgfilter nopad\' type = "submit">Išsaugoti</button></td></tr>';
$pforma .= '</table>';
$pforma .= '</form>';



if (isset($oldstyle) && $oldstyle == "1") {
?>
<tr><td width="50%" class="title">Jūsų duomenys</td><td class="title">Mūsų duomenys</td></tr>
<?php
} else {
?>
<tr><th>Jūsų duomenys</th><td class="emptycol">&nbsp;</td><th>Mūsų duomenys</th><td class="emptycol">&nbsp;</td><td valign="top" rowspan="2">
<?php
echo $pforma;
?>
</td></tr>
<?php
}
?>
<tr><td class="info bleft">
<?php 
if (!empty($minfo)) {
	echo @iconv('windows-1257', 'UTF-8', "<span class='sbold'>".$minfo["N08_PAV"]."</span>");
	echo @iconv('windows-1257', 'UTF-8', "<br>".$minfo["N08_ADR"].$minfo["N08_PASTAS"].$minfo["N08_KODAS_VS"]);
	echo "<br>Įm. kodas ".$minfo["N08_IM_KODAS"];
	echo "<br>PVM kodas ".$minfo["N08_PVM_KODAS"];
	echo "<br>Atstovas ".@iconv('windows-1257', 'UTF-8', $minfo["N08_ATSTOVAS"]);
	echo "<br>Telefonas ".@iconv('windows-1257', 'UTF-8', $minfo["N08_TEL"]);
	echo "<br>Mobilusis telefonas ".@iconv('windows-1257', 'UTF-8', $minfo["N08_MOB_TEL"]);
	echo "<br>Faksas ".@iconv('windows-1257', 'UTF-8', $minfo["N08_FAX_NUM"]);
	echo "<br>Interneto adresas ".@iconv('windows-1257', 'UTF-8', $minfo["N08_E_MAIL"]);
	echo "<br><br>Sąskaitų apmokėjimo terminas ".@iconv('windows-1257', 'UTF-8', $minfo["n08_kodas_ts_p"]);
	echo "<br>E-mail ".@iconv('windows-1257', 'UTF-8', $minfo["r06_pav"]);
 } else {?>
Nieko nerasta.
<?php }?>
</td>
<?php
if (!isset($oldstyle) || $oldstyle != "1") {
	echo "<td>&nbsp;</td>";
}
?>
<td class="info bright">
<?php 
if (!empty($ourinfo)) {
	echo @iconv('windows-1257', 'UTF-8', "<span class='sbold'>".$ourinfo["N08_PAV"]."</span>");
	echo @iconv('windows-1257', 'UTF-8', "<br>".$ourinfo["N08_ADR"].$ourinfo["N08_PASTAS"].$ourinfo["N08_KODAS_VS"]);
	echo "<br>Įm. kodas ".$ourinfo["N08_IM_KODAS"];
	echo "<br>PVM kodas ".$ourinfo["N08_PVM_KODAS"];
	echo "<br>Atstovas ".@iconv('windows-1257', 'UTF-8', $ourinfo["N08_ATSTOVAS"]);
	echo "<br>Telefonas ".@iconv('windows-1257', 'UTF-8', $ourinfo["N08_TEL"]);
	echo "<br>Mobilusis telefonas ".@iconv('windows-1257', 'UTF-8', $ourinfo["N08_MOB_TEL"]);
	echo "<br>Faksas ".@iconv('windows-1257', 'UTF-8', $ourinfo["N08_FAX_NUM"]);
	echo "<br>Interneto adresas ".@iconv('windows-1257', 'UTF-8', $ourinfo["N08_E_MAIL"]);
	echo "<br><br>" .@iconv('windows-1257', 'UTF-8', $saskinfo["N34_PAV"] . " " . $saskinfo["N33_KODAS_WS"]);
	echo "<br>" . $saskinfo["N33_S_KODAS"];

 } else {?>
Nieko nerasta.
<?php }?>
</td>
<?php
if (isset($oldstyle) && $oldstyle == "1") {
?>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td class="info ball">
<?php
echo $pforma;
?>
</td>
<?php
}
?>
<td>&nbsp;</td></tr>
</table>
<?php
include("footer.php");
?>